import threading
import os
import random
import time

"""
多线程的设计: 
    import threading
    多线程相比多进程的区别:
        多线程更加轻量化,使得io处理更加迅速
        
    # 面向对象的设计模式
        继承Thread类,重写run()方法
        设置守护进程,thread.setDaemon(True)
        
        
"""

class ThreadDog(threading.Thread):
    def __init__(self,thread_name,delay,count):
        super().__init__(name=thread_name)
        self.__delay = delay
        self.__count = count

    # 线程的主体方法
    def run(self):
        for i in range(self.__count):
            time.sleep(self.__delay)
            print('[{}]  id:[{}]  叫了第{}声'.format(threading.current_thread().name, threading.current_thread().ident, i))


class ThreadChain(threading.Thread):
    def __init__(self,thread_name):
        super().__init__(name=thread_name)

    def buckle(self):
        while 1:
            print('修钩别扣住了.....')
            time.sleep(1)

    def run(self) -> None:
        self.buckle()


def main():
    th_dogs = [ThreadDog(thread_name='修钩{}'.format(item),delay=1,count=3) for item in range(1)]
    th_chain = ThreadChain(thread_name='狗链子')
    th_chain.setDaemon(True)
    th_chain.start()
    for th_dog in th_dogs:
        th_dog.start()
    for th_dog in th_dogs:
        th_dog.join()


if __name__ == '__main__':
    main()